﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Profiling.Sampler
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.Collections.Generic;
using Unity.Profiling.LowLevel.Unsafe;
using UnityEngine.Bindings;
using UnityEngine.Scripting;

#nullable disable
namespace UnityEngine.Profiling
{
  /// <summary>
  ///   <para>Provides control over a CPU Profiler label.</para>
  /// </summary>
  [NativeHeader("Runtime/Profiler/ScriptBindings/Sampler.bindings.h")]
  [UsedByNativeCode]
  public class Sampler
  {
    internal IntPtr m_Ptr;
    internal static Sampler s_InvalidSampler = new Sampler();

    internal Sampler()
    {
    }

    internal Sampler(IntPtr ptr) => this.m_Ptr = ptr;

    /// <summary>
    ///   <para>Returns true if Sampler is valid. (Read Only)</para>
    /// </summary>
    public bool isValid => this.m_Ptr != IntPtr.Zero;

    /// <summary>
    ///   <para>Returns Recorder associated with the Sampler.</para>
    /// </summary>
    /// <returns>
    ///   <para>Recorder object associated with the Sampler.</para>
    /// </returns>
    public Recorder GetRecorder()
    {
      return new Recorder(new ProfilerRecorderHandle((ulong) this.m_Ptr.ToInt64()));
    }

    /// <summary>
    ///   <para>Returns Sampler object for the specific CPU Profiler label.</para>
    /// </summary>
    /// <param name="name">Profiler Sampler name.</param>
    /// <returns>
    ///   <para>Sampler object which represents specific profiler label.</para>
    /// </returns>
    public static Sampler Get(string name)
    {
      IntPtr marker = ProfilerUnsafeUtility.GetMarker(name);
      return marker == IntPtr.Zero ? Sampler.s_InvalidSampler : new Sampler(marker);
    }

    public static int GetNames(List<string> names)
    {
      List<ProfilerRecorderHandle> outRecorderHandleList = new List<ProfilerRecorderHandle>();
      ProfilerRecorderHandle.GetAvailable(outRecorderHandleList);
      if (names != null)
      {
        if (names.Count < outRecorderHandleList.Count)
        {
          names.Capacity = outRecorderHandleList.Count;
          for (int count = names.Count; count < outRecorderHandleList.Count; ++count)
            names.Add((string) null);
        }
        int index = 0;
        foreach (ProfilerRecorderHandle handle in outRecorderHandleList)
        {
          ProfilerRecorderDescription description = ProfilerRecorderHandle.GetDescription(handle);
          names[index] = description.Name;
          ++index;
        }
      }
      return outRecorderHandleList.Count;
    }

    /// <summary>
    ///   <para>Sampler name. (Read Only)</para>
    /// </summary>
    public string name => ProfilerUnsafeUtility.Internal_GetName(this.m_Ptr);
  }
}
